package com.mt.customer.controller;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.customer.api.service.ICustomerService;
import com.mt.customer.entity.CustomerEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@CrossOrigin
@RestController
public class CustomerController {

    @Autowired
    ICustomerService customerService;

    @GetMapping("/customer/findInfo")
    public ServiceResult<CustomerEntity> findInfo(@RequestParam Map<String, Object> params) {
        return customerService.findInfo(params);
    }

    @GetMapping("/customer/findList/{page}/{size}")
    public ServiceResult<List<CustomerEntity>> findList(@RequestParam Map<String, Object> params,
            @PathVariable(value = "page") Integer page, @PathVariable(value = "size") Integer size) {
        PagerInfo pagerInfo = null;
        if (page > 0 && size > 0) {
            pagerInfo = new PagerInfo();
            pagerInfo.setPageIndex(page);
            pagerInfo.setPageSize(size);
        }
        return customerService.findList(params, pagerInfo);
    }

    @PostMapping("/customer/doInsert")
    public ServiceResult<Integer> doInsert(@RequestBody CustomerEntity customerEntity) {
        return customerService.doInsert(customerEntity);
    }

    @PostMapping("/customer/doUpdate")
    public ServiceResult<Integer> doUpdate(@RequestBody CustomerEntity customerEntity) {
        return customerService.doUpdate(customerEntity);
    }
}
